let app = getApp()
Component({
    properties: { 
      nodata:{ type: Number,
        observer: function(newVal, oldVal) {
          this.updatedatanum()
        }},
      refreshData: {
        type: Array,
        observer: function(newVal, oldVal) {
          this.updateRate()
        }
      }
      },
      data:{
        loginShow:false
      },
    lifetimes: {
        attached: function () {
         }   
      },
    methods: {
      updatedatanum:function(){
        var nodata=this.data.nodata
        this.setData({
          nodata:nodata
        })
      },
      userinfo:function(e){
        var index=e.currentTarget.dataset.index
        var t=this.data.infoArr[index]
        var a = "/business-service/pages/staff_customer/customerInfo/index?imgUrl=" + encodeURIComponent(t.user_headimg) + "&name=" + t.nick_name + "&from=" + t.source + "&cus_id=" + t.cus_id + "&user_openid=" + t.openid + "&md5=" + t.md5 + "&phone=" + t.phone + "&user_id=" + t.user_id;
        wx.navigateTo({
          url:a
        })
      },
      setcustomer:function(e){
        var that=this
        var user_id=e.currentTarget.dataset.user_id;
        var index=e.currentTarget.dataset.index;
        var infoArr=this.data.infoArr
        wx.request({
          url: app.globalData.siteroot,
           data: {
             do:'Message_getPushTmplIds',
             temp_name:'leave_message,place_order,visit_message'
          },
         success: function(res) {
            var leave_message=res.data.info.leave_message
            wx.requestSubscribeMessage({
                tmplIds: [leave_message],
                success (res) {
                    wx.request({
                        url: app.globalData.siteroot,
                         data: {
                           do:'Customer_intention',
                           user_id:user_id,
                           staff_id:wx.getStorageSync('staff_bind_id')
                        },
                       success: function(res) {
                        infoArr[index]['is_intention']=1
                        that.setData({
                          infoArr:infoArr
                        })
                        wx.showToast({
                          title: '设置成功！',
                          icon: 'none',
                          duration: 1500
                        })
                       }
                      })
                }
            })
         }
        })
      },
      shield:function(e){
        var that=this
        var user_id=e.currentTarget.dataset.user_id;
        var index=e.currentTarget.dataset.index;
        var infoArr=this.data.infoArr
        wx.request({
          url: app.globalData.siteroot,
           data: {
             do:'Message_getPushTmplIds',
             temp_name:'leave_message,place_order,visit_message'
          },
         success: function(res) {
            var leave_message=res.data.info.leave_message
            wx.requestSubscribeMessage({
                tmplIds: [leave_message],
                success (res) {
                    wx.request({
                        url: app.globalData.siteroot,
                         data: {
                           do:'Customer_shield',
                           user_id:user_id,
                           staff_id:wx.getStorageSync('staff_bind_id')
                        },
                       success: function(res) {
                        wx.showToast({
                          title: '屏蔽成功！',
                          icon: 'none',
                          duration: 1500
                        })
                        that.triggerEvent ('getdata',user_id)
                       }
                      })
                }
            })
         }
        })
      },
      sendmsg:function(e){
        var index=e.currentTarget.dataset.index;
        var infoArr=this.data.infoArr
        var t=infoArr[index]
        wx.navigateTo({
          url: "/business-service/pages/staff_customer/sendmsg?id=" + t.user_id + "&cus_id=" + t.cus_id + "&imgUrl=" + encodeURIComponent(t.user_headimg) + "&name=" + t.nick_name + "&md5=" + t.md5 + "&from=" + t.source + "&user_openid=" + t.openid + "&is_intention=" + t.is_intention
        })
      },
      updateRate:function(){
        var refreshData=this.data.refreshData
        this.setData({
          infoArr:refreshData
        })
      }
    }
});
